﻿using UnityEngine;
using System.Collections;

public class text : MonoBehaviour {


	public string SortingLayerName = "Default";
	public int SortingOrder = 0;
	public Champion champion;
	public Nexus nexus;
	public TextMesh mesh;
	public bool healthText;
	public bool nexusHealth;
	
	void Awake ()
	{
		gameObject.GetComponent<MeshRenderer> ().sortingLayerName = SortingLayerName;
		gameObject.GetComponent<MeshRenderer> ().sortingOrder = SortingOrder;
		if(!nexusHealth)
			champion = transform.parent.transform.parent.gameObject.GetComponent<Champion>();
		else
			nexus = transform.parent.transform.parent.gameObject.GetComponent<Nexus>();
		mesh = GetComponent<TextMesh>();
	}
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		if(!nexusHealth){
			if(healthText)
				mesh.text = champion.health.ToString();
			else
				mesh.text = champion.attack.ToString();
		}
		else{
			mesh.text = nexus.Health.ToString();
		}
	}
}
